package cn.com.czpb.client.module.news.view;

import android.app.Activity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;

import java.util.List;

import cn.com.czpb.client.R;
import cn.com.czpb.client.app.MyActivitymanager;
import cn.com.czpb.client.model.news.NewsBean;
import cn.com.czpb.client.module.news.adapter.NewsItemListViewAdapterNew;
import cn.com.czpb.client.utils.LogUtils;
import cn.com.czpb.client.utils.PageCtrl;
import cn.com.czpb.client.utils.SPUtil;

/**
 * Created by Administrator on 2017/12/28.
 */

public class TopLanMuInZhuanTi implements BaseQuickAdapter.OnItemChildClickListener, View.OnClickListener {
    private Activity activity;
    private TextView lanmuname;
    private RecyclerView recycv;
    private ImageView shareimg;
    private View rootView;
    private String cname;
    private String newsurl;
    private String imgurl;
    private NewsItemListViewAdapterNew adapter;
    private List<NewsBean> list;
    public TopLanMuInZhuanTi(Activity activity) {
        this.activity = activity;
        adapter = new NewsItemListViewAdapterNew(activity,list,false);
        adapter.setOnItemChildClickListener(this);
        initView();
    }
    public View getView(){
        return rootView;
    }
    private void initView() {
        LayoutInflater layoutInflater = LayoutInflater.from(activity);
        rootView = layoutInflater.inflate(R.layout.view_zhuanti_lanmu,null);
        lanmuname = rootView.findViewById(R.id.lanmu_name);
        shareimg = rootView.findViewById(R.id.lanmu_share);
        recycv = rootView.findViewById(R.id.zhuanti_lanmu_recycv);
        recycv.setLayoutManager(new LinearLayoutManager(activity));
        recycv.setAdapter(adapter);
        recycv.setFocusable(false);
        shareimg.setOnClickListener(this);
    }
    public void setImgurl(String imgurl){
        this.imgurl = imgurl;
    }
    public void setNewsurl(String newsurl){
        this.newsurl = newsurl;
    }
    public void setLanmuname(String name) {
        cname = name;
        lanmuname.setText(name);
    }
    public void setData(List<NewsBean> list){
        adapter.setNewData(list);
        adapter.notifyDataSetChanged();
    }
    public static TopLanMuInZhuanTi instance(Activity activity){
        return new TopLanMuInZhuanTi(activity);
    }

    @Override
    public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
        final NewsBean newsBean = (NewsBean) adapter.getItem(position);
        switch (view.getId()) {
            case R.id.newsItem_root:
                ////REFACTOR: 2017/8/18 添加浏览量bug
                MyActivitymanager.pushActivity(activity, newsBean, newsBean.getTid(), "newsitem",newsBean.getRvalue());
                LogUtils.e("rtype--"+newsBean.getRtype());
                break;
        }
    }

    @Override
    public void onClick(View v) {
        if(SPUtil.getInstance().getUser() != null) {
//            if (null != ndb.getImgs() && ndb.getImgs().size() > 0) {
//                imgurl = ndb.getImgs().get(0);
//            }
//            ImageUtils.saveDrawableById(R.drawable.share_code,"shareapklogo", Bitmap.CompressFormat.JPEG,activity);
//            String sharelogourl = Environment.getExternalStorageDirectory()+"/shareapklogo";
//            String link = newsurl;
//            ShareDialog dialog = new ShareDialog(activity, R.style.Sharedialog,cname, link, imgurl, 1,sharelogourl);
//            dialog.show();
        }else{
            PageCtrl.start2LoginActivity(activity);
        }
        LogUtils.e("cname:"+cname+"newsurl:"+newsurl);
    }
}
